package org.ocelot.tunes4j.taggers;


import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jaudiotagger.audio.mp3.MP3File;
import org.ocelot.tunes4j.beans.AudioObject;

import com.dusbabek.lib.id3.Reader;
import com.dusbabek.lib.id3.Tag;


public class JavaID3TaggerImpl implements Tagger {

	private Log log = LogFactory.getLog(this.getClass());
	
	@Override
	public AudioObject parse(File sourceFile) {
		AudioObject mp3Bean = null;
		MP3File mp3file;
	
		mp3Bean = new AudioObject();
		mp3Bean.setPath(sourceFile.getParent());
		mp3Bean.setFileName(sourceFile.getName());
		try {
			FileInputStream in = new FileInputStream(sourceFile);
			Reader reader = new Reader();
				Tag tag = reader.read(in,sourceFile.length());
			mp3Bean.setArtist(tag.getArtist());
			mp3Bean.setTitle(tag.getTitle() );
			mp3Bean.setAlbum(tag.getAlbum());
			in.close();
		} catch (FileNotFoundException e) {
			System.out.println("Error en el archivo: " + sourceFile.getPath());
			e.printStackTrace();
		} catch (IOException e) {
			System.out.println("Error en el archivo: " + sourceFile.getPath());
			e.printStackTrace();
		}

		 
		
		return mp3Bean;
	}

	@Override
	public void save(File sourceFile, AudioObject bean) {
		// TODO Auto-generated method stub
		
	}

}
